package com.khalil.kkadmin.module.ai.application.service;

import com.khalil.kkadmin.module.ai.application.domain.AiApplication;
import com.khalil.kkadmin.module.ai.application.domain.AiApplicationRepository;
import com.khalil.kkadmin.module.ai.application.dto.AiApplicationCreateDto;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class AiApplicationManagerImpl implements AiApplicationManager {
    private final AiApplicationRepository repository;

    public AiApplicationManagerImpl(AiApplicationRepository repository) {
        this.repository = repository;
    }

    @Override
    public AiApplication create(AiApplicationCreateDto createDto) {
        AiApplication aiApplication = new AiApplication();
        BeanUtils.copyProperties(createDto, aiApplication);
        return repository.save(aiApplication);
    }

    @Override
    public AiApplication update(AiApplication aiApplication) {
        return repository.save(aiApplication);
    }

    @Override
    public void delete(Long id) {
        repository.deleteById(id);
    }

    @Override
    public AiApplication get(Long id) {
        return repository.findById(id).orElse(null);
    }

    @Override
    public List<AiApplication> list() {
        return repository.findAll();
    }
}
